package service

import (
	"image/color"
	"github.com/mojocn/base64Captcha"
)

var store = base64Captcha.DefaultMemStore

func MakeCaptcha() (id, b64s string, err error) {
	var driver base64Captcha.Driver
	var driverString base64Captcha.DriverString

	captchaConfig := base64Captcha.DriverString{
		Height:          64,
		Width:           220,
		NoiseCount:      0,
		ShowLineOptions: 2 | 4,
		Length:          4,
		Source:          "1234567890qwertyuioplkjhgfdsazxcvbnm",
		BgColor: &color.RGBA{
			R: 233,
			G: 233,
			B: 233,
			A: 1,
		},
		Fonts: []string{"wqy-microhei.ttc"},
	}
 
	driverString = captchaConfig
	driver = driverString.ConvertFonts()
	captcha := base64Captcha.NewCaptcha(driver, store)
	lid, lb64s, lerr := captcha.Generate()
	return lid, lb64s, lerr
}

func VerifyCaptcha(id string, capt string) bool {
	if store.Verify(id, capt, false) {
		return true
	} else {
		return false
	}
}